home *** CD-ROM | disk | FTP | other *** search
- //
- // Fichero: FUNCWIN.CPP
- //
- // Versi≤n: 1.0
- // Autor: Antonio M. EstΘvez Lorenzo
- // Prop≤sito: WinMain()
- // Ventana principal de la aplicaci≤n
- //
-
- #include <windows.h>
- #include <owl.h>
- #pragma hdrstop
-
- #include <bwcc.h>
- #include "Child.h"
- #include "FuncDlg.h"
- #include "oleserv.h"
- #include "Ejemplos.h"
- #include "strings.h"
- #include "Mensajes.h"
- #include "Mensajes.ids"
-
- HWND hWindPrev;
-
- TDatosEcuPar tmpEcuPar=
- {{"COS(A)COS(B)","COS(A)SEN(B)","SEN(A)",
- "Ecuaciones paramΘtricas",
- "-PI/2","PI/2", "0","2PI", "16","22",
- "15","15","15", "0","0","0", "0","0","0"},
- {1,0,0,0,0,0, 1, 1,0,"1/2","60", 0,0,1,0, "5", 1,0,0,0,
- 0,359,120, 0,359,120, 120,120, 135},
- {"0","0","0", "1","1","1", "","",0, 1,0,0,0},
- 0, {ChildMinX, ChildMinY}};
-
- static TDatosFunc2V tmpFunc2V=
- {{"X^3-3X*Y^2",
- "Funci≤n de 2 variables",
- "-1","1", "-1","1", "20","20",
- "10","10","10", "0","0","0", "0","0","0"},
- {1,0,0,0,0,0, 1, 1,0,"1/2","60", 0,0,1,0, "5", 1,0,0,0,
- 0,359,120, 0,359,120, 120,120, 135},
- {"0","0","0", "1","1","1", "","",0, 1,0,0,0},
- 0, {ChildMinX, ChildMinY}};
-
- extern BOOL HayMensaje;
- static DWORD MemoriaLibre;
-
- char ProgDirect[260];
- char FichAyuda[260];
- char *SecWindow = "Func3D";
- char *ItemCoord[5]= {"Coord X", "Coord Y", "Ancho", "Alto","Modo"};
- char *CoordInic[5]= {"20","20","600","400","0"};
-
- BOOL PulsadaF1= FALSE;
-
- BOOL NoEsAyuda(int idAyuda)
- {
- if(idAyuda && PulsadaF1)
- {
- WinHelp(GetApplicationObject()->MainWindow->HWindow,
- FichAyuda, HELP_CONTEXT, idAyuda);
- return (PulsadaF1= FALSE);
- }
- return TRUE;
- }
-
-
- /* TProgWindow */
-
- class TProgWindow : public TOLEWindMDI
- {
- HICON Icono;
- BOOL HayEjemplos;
- TWindow *Child;
- TWindowsObject *WindCalc;
- void GetDatIni();
- void SetDatIni();
- void NuevaSuperf(BOOL EsEcuPar, int Mensaje, BOOL embedded= FALSE,
- LPVOID Datos= NULL, TSuperf **Sup= NULL, LPARAM pDoc= NULL);
- protected:
- virtual void GetWindowClass(WNDCLASS& AWndClass);
- virtual void Paint(HDC PaintDC, PAINTSTRUCT _FAR &PaintInfo);
- virtual void SetupWindow();
- virtual BOOL CanClose();
- virtual PTWindowsObject InitChild();
- void WMEnterIdle(RTMessage) = [WM_FIRST + WM_ENTERIDLE];
- void WMSize(RTMessage) = [WM_FIRST + WM_SIZE];
- void CMArrangeIcons(RTMessage) = [CM_FIRST + CM_ARRANGEICONS];
- void CMTileChildren(RTMessage) = [CM_FIRST + CM_TILECHILDREN];
- void CMCascadeChildren(RTMessage)= [CM_FIRST + CM_CASCADECHILDREN];
- void CMCloseChildren(RTMessage) = [CM_FIRST + CM_CLOSECHILDREN];
- void SelecEcuPar(RTMessage) = [CM_FIRST + cmEcuPar];
- void SelecFunc2V(RTMessage) = [CM_FIRST + cmFunc2V];
- void Calculadora(RTMessage) = [CM_FIRST + cmCalculadora];
- void Ejemplos(RTMessage) = [CM_FIRST + cmEjemplos];
- void About(RTMessage) = [CM_FIRST + cmAbout];
- void Terminar(RTMessage) = [CM_FIRST + cmTerminar];
- void FuncDef(RTMessage) = [CM_FIRST + cmFuncDef];
- void Ayuda(RTMessage) = [CM_FIRST + cmAyuda];
- void IndAyuda(RTMessage) = [CM_FIRST + cmIndAyuda];
- void Setup(RTMessage) = [ID_FIRST + cmSetup];
- void FinEmbedded(RTMessage) = [ID_FIRST + cmFinEmbedded];
- void CopiaEjemplo(RTMessage) = [ID_FIRST + cmCopiaEjemplo];
- public:
- TProgWindow(LPSTR Titulo, PTModule Modulo= NULL);
- void CreaChildWind(LPVOID Datos, LPOLESERVERDOC pDoc,
- TWindow **Wind, TSuperf **Sup);
- void WriteMemor();
- };
-
- TProgWindow::TProgWindow(LPSTR Titulo, PTModule Modulo)
- :TOLEWindMDI(Titulo,"Menu",Modulo)
- {
- ChildMenuPos= 2;
- GetDatIni();
- HayEjemplos= FALSE;
- }
-
- void TProgWindow::SetupWindow()
- {
- TOLEWindMDI::SetupWindow();
-
- hWindPrev= HWindow;
- }
-
- void TProgWindow::GetWindowClass(WNDCLASS& AWndClass)
- {
- TWindow::GetWindowClass(AWndClass);
- AWndClass.style|= CS_BYTEALIGNCLIENT;
- AWndClass.hIcon= Icono= LoadIcon(GetApplication()->hInstance,"Func3D");
- }
-
- void TProgWindow::WMSize(RTMessage Msg)
- {
- TMDIFrame::WMSize(Msg);
-
- HayMensaje= (Msg.WParam== SIZE_MINIMIZED);
- }
-
- void TProgWindow::GetDatIni()
- {
- char Fich[270];
- char Num[10];
- int i,*Coord= (int*)&Attr.X;
-
- StrUne(Fich,ProgDirect,"FUNCWIN.INI");
- for(i= 0; i< 4; i++)
- {
- GetPrivateProfileString(SecWindow,ItemCoord[i],CoordInic[i],
- Num,sizeof(Num),Fich);
- StToInt(Num,Coord++);
- }
- GetPrivateProfileString(SecWindow,ItemCoord[i],CoordInic[i],
- Num,sizeof(Num),Fich);
- if(Num[0]== '1')
- GetApplicationObject()->nCmdShow = SW_SHOWMAXIMIZED;
- }
-
- void TProgWindow::SetDatIni()
- {
- char Fich[270];
- char Num[10];
- int i,*Coord= (int*)&Attr.X;
-
- StrUne(Fich,ProgDirect,"FUNCWIN.INI");
- for(i= 0; i< 4; i++)
- {
- IntToSt(Num,*Coord++);
- WritePrivateProfileString(SecWindow,ItemCoord[i],Num,Fich);
- }
- if(IsZoomed(HWindow))
- Num[0]= '1';
- else
- Num[0]= '0';
- Num[1]= '\0';
- WritePrivateProfileString(SecWindow,ItemCoord[i],Num,Fich);
- }
-
- BOOL TProgWindow::CanClose()
- {
- TOLEProg *Prog = (TOLEProg*)GetApplicationObject();
- TOLEServer *Server= Prog->pServer;
-
- if(OleRevokeServer(Server->lhServer)== OLE_WAIT_FOR_RELEASE)
- Prog->Wait(Server->fRelease);
- WinHelp(HWindow,FichAyuda,HELP_QUIT,NULL);
- SetDatIni();
- DestroyIcon(Icono);
- return TRUE;
- }
-
- void TProgWindow::FinEmbedded(RTMessage Msg)
- {
- OleRevokeServerDoc(((TOLEDocument*)Msg.LParam)->lhDoc);
- }
-
- void TProgWindow::Setup(RTMessage Msg)
- {
- if(NoEsAyuda(cmSetup))
- OleSavedServerDoc(((TOLEDocument*)Msg.LParam)->lhDoc);
- }
-
- PTWindowsObject TProgWindow::InitChild()
- {
- return Child;
- }
-
- void TProgWindow::NuevaSuperf(BOOL EsEcuPar, int Mensaje, BOOL embedded,
- LPVOID Datos, TSuperf **Sup, LPARAM pDoc)
- {
- if(EsEcuPar)
- {
- if(!Datos)
- Datos= &tmpEcuPar;
- Child= new TChildEcuPar(this, (TDatosEcuPar*)Datos, Sup, embedded, pDoc);
- }
- else
- {
- if(!Datos)
- Datos= &tmpFunc2V;
- Child= new TChildFunc2V(this, (TDatosFunc2V*)Datos, Sup, embedded, pDoc);
- }
- SendMessage(HWindow, WM_COMMAND, CM_CREATECHILD, NULL);
- if(Mensaje)
- SendMessage(Child->HWindow, WM_COMMAND, Mensaje, NULL);
- }
-
- void TProgWindow::CreaChildWind(LPVOID Datos, LPOLESERVERDOC pDoc,
- TWindow **Wind, TSuperf **Sup)
- {
- BOOL EsEcuPar;
- int Mens= NULL;
-
- if(!Datos)
- {
- TTipoSup TipoSup;
- TipoSup.EcuPar= TRUE;
- TipoSup.Func2V= FALSE;
- GetModule()->ExecDialog(new TDlgTipoSup(NULL,&TipoSup));
- EsEcuPar= TipoSup.EcuPar;
- Mens= cmEditar;
- }
- else
- EsEcuPar= *((int*)Datos)++;
-
- NuevaSuperf(EsEcuPar, Mens, TRUE, Datos, Sup, (long)pDoc);
- *Wind= Child;
- }
-
- void TProgWindow::CopiaEjemplo(RTMessage Msg)
- {
- NuevaSuperf(TRUE, cmDibujar, FALSE, (LPVOID)Msg.LParam);
- }
-
- void TProgWindow::SelecEcuPar(RTMessage)
- {
- if(NoEsAyuda(cmEcuPar))
- NuevaSuperf(TRUE, cmEditar);
- }
-
- void TProgWindow::SelecFunc2V(RTMessage)
- {
- if(NoEsAyuda(cmFunc2V))
- NuevaSuperf(FALSE, cmEditar);
- }
-
- void TProgWindow::Terminar(RTMessage)
- {
- if(NoEsAyuda(cmTerminar))
- if(Mensaje(HWindow,MensTerminar,MensNombProg,
- MB_ICONQUESTION | MB_YESNO)== IDYES)
- SendMessage(HWindow,WM_COMMAND,CM_EXIT,NULL);
- }
-
- void TProgWindow::Calculadora(RTMessage)
- {
- if(NoEsAyuda(cmCalculadora))
- {
- if(MF_GRAYED & GetMenuState(GetMenu(HWindow), cmCalculadora, MF_BYCOMMAND))
- {
- ShowWindow(WindCalc->HWindow, SW_SHOWNORMAL);
- SendMessage(WindCalc->HWindow, WM_ACTIVATE, WA_CLICKACTIVE, NULL);
- }
- else
- GetModule()->MakeWindow(WindCalc= new TDlgCalcula(this));
- }
- }
-
- void TProgWindow::FuncDef(RTMessage)
- {
- if(NoEsAyuda(cmFuncDef))
- GetModule()->ExecDialog(new TDlgFuncDef(this));
- }
-
- void TProgWindow::Ejemplos(RTMessage)
- {
- if(NoEsAyuda(cmEjemplos))
- {
- BOOL Hay= TRUE;
- if(!HayEjemplos)
- {
- HayEjemplos= TRUE;
- if(!TDlgEjemplos::HayEjemplos(ProgDirect))
- {
- HMENU Menu= GetMenu(HWindow);
- EnableMenuItem(Menu, cmEjemplos, MF_BYCOMMAND | MF_GRAYED);
- Hay= FALSE;
- }
- }
- if(Hay)
- GetModule()->ExecDialog(new TDlgEjemplos(this));
- }
- }
-
- void TProgWindow::About(RTMessage)
- {
- if(NoEsAyuda(cmAbout))
- GetModule()->ExecDialog(new TWindDlg(this,dgAbout));
- }
-
- void TProgWindow::IndAyuda(RTMessage)
- {
- PulsadaF1= FALSE;
- WinHelp(HWindow,FichAyuda,HELP_CONTENTS,NULL);
- }
-
- void TProgWindow::Ayuda(RTMessage)
- {
- PulsadaF1= TRUE;
- NoEsAyuda(hlpWindow);
- }
-
- void TProgWindow::CMArrangeIcons(RTMessage Msg)
- {
- if(NoEsAyuda(hlpMenuVentanas))
- TOLEWindMDI::CMArrangeIcons(Msg);
- }
-
- void TProgWindow::CMTileChildren(RTMessage Msg)
- {
- if(NoEsAyuda(hlpMenuVentanas))
- TOLEWindMDI::CMTileChildren(Msg);
- }
- void TProgWindow::CMCascadeChildren(RTMessage Msg)
- {
- if(NoEsAyuda(hlpMenuVentanas))
- TOLEWindMDI::CMCascadeChildren(Msg);
- }
- void TProgWindow::CMCloseChildren(RTMessage Msg)
- {
- if(NoEsAyuda(hlpMenuVentanas))
- TOLEWindMDI::CMCloseChildren(Msg);
- }
-
- void TProgWindow::WMEnterIdle( RTMessage Msg )
- {
- if((Msg.WParam == MSGF_MENU ) &&
- ((GetKeyState( VK_F1 ) & 0x8000) != 0) )
- {
- PulsadaF1= TRUE;
- PostMessage(HWindow, WM_KEYDOWN, VK_RETURN, NULL );
- }
- }
-
- void TProgWindow::Paint(HDC PaintDC, PAINTSTRUCT _FAR &PaintInfo)
- {
- WriteMemor();
- TOLEWindMDI::Paint(PaintDC, PaintInfo);
- }
-
- void TProgWindow::WriteMemor()
- {
- char buff[30];
- HDC Hdc = GetWindowDC(HWindow);
- int PosY= GetSystemMetrics(SM_CYCAPTION) +
- GetSystemMetrics(SM_CYFRAME);
- wsprintf(buff,"%lu bytes libres.",MemoriaLibre);
- TextOut(Hdc,350,PosY,buff,LongStr(buff));
- ReleaseDC(HWindow,Hdc);
- }
-
-
- /* TProgram */
-
- class TProgram: public TOLEProg
- {
- protected:
- virtual void InitInstance();
- virtual void InitMainWindow();
- virtual void IdleAction();
- public:
- TProgram(LPSTR Nombre, HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- : TOLEProg(Nombre, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
- };
-
- void CreaVariables();
-
- void TProgram::InitMainWindow()
- {
- BWCCGetVersion();
- MainWindow= new TProgWindow(Name);
- }
-
- void TProgram::InitInstance()
- {
- TOLEProg::InitInstance();
- HAccTable= LoadAccelerators(hInstance,MAKEINTRESOURCE(Acelerador));
- CreaVariables();
- SetupMenu();
- if(!Embedded)
- ExecDialog(new TWindDlg(NULL,dgAbout));
- }
-
- void TProgram::IdleAction()
- {
- DWORD Memor= GetFreeSpace(NULL);
- if(Memor!= MemoriaLibre)
- {
- MemoriaLibre= Memor;
- ((TProgWindow*)MainWindow)->WriteMemor();
- }
- }
-
-
- /* WINMAIN */
-
- int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,
- LPSTR lpCmdLine, int nCmdShow)
- {
- if(hPrevInst)
- {
- asm{
- mov ax,hPrevInst
- inc ax
- push ds
- mov ds,ax
- mov ax,hWindPrev
- pop ds
- mov hWindPrev,ax
- }
- if(IsIconic(hWindPrev))
- ShowWindow(hWindPrev, SW_RESTORE);
- SetActiveWindow(hWindPrev);
- return FALSE;
- }
-
- char buff[270];
- GetModuleFileName(hInstance,ProgDirect,sizeof(ProgDirect));
- GetDirStr(ProgDirect);
- StrUne(FichAyuda,ProgDirect,"FUNCWIN.HLP");
- StrUne(buff,ProgDirect,"BORTE.FON");
- AddFontResource(buff);
- SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
- TProgram Program("FUNC3D: Dibuja superficies en 3 dimensiones",
- hInstance, hPrevInst, lpCmdLine, nCmdShow);
- Program.Run();
- if(RemoveFontResource(buff))
- SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
- return Program.Status;
- }
-